package com.service.impl;

import com.dao.impl.LoginImpl;
import com.service.LoginService;
import com.entity.Clients;

import java.util.List;

import static com.util.Vessel.loginImpl;
import static com.util.Vessel.scanner;


public class LoginSerImpl implements LoginService {


    //注册
    @Override
    public void signUpService() {
        System.out.println("请输入用户名:");
        String cName = scanner.next();
        System.out.println("请设置密码:");
        String cPassword = scanner.next();
        List<Clients> clientsList = loginImpl.signUp(cName,cPassword);
        for (Clients client : clientsList){
            System.out.println("账号\t\t\t" + "姓名" + "\t\t\t\t" + "密码" + "\t\t\t" + "性别" + "\t\t\t\t" + "VIP" + "\t\t\t\t" + "余额");
            System.out.println(client.getcId() + "\t\t\t" + client.getcName() + "\t\t\t" + client.getcPassword()
                    + "\t\t\t" + client.iscVip() + "\t\t\t" +
                    client.getcBalance() + "\t\t\t" );
        }
    }

    //登录
    @Override
    public int signInService() {
        int id = -1;
        System.out.println("请输入账号:");
        int cId = scanner.nextInt();
        System.out.println("请输入密码:");
        String cPassword = scanner.next();
        if (cId==0 && cPassword.equals("11111")){
            id = 0;
        }else {
            List<Clients> clientsList = loginImpl.signIn(cId,cPassword);
            for (Clients client : clientsList){
                if (client.getcId() > 0){
                    System.out.println("登录成功!!!");
                    id = client.getcId();
                }
            }
        }
        return id;
    }
}
